{literal}
<script type="text/javascript">
    $(document).ready(function(){

		var cod = "{/literal}{$proposta->id}{literal}";
		var status_da_proposta = "{/literal}{$proposta->int_status}{literal}";
		var vlr_status_cancelada = {/literal}{php}echo Constantes::cteCodStatusPropostaCancelada{/php}{literal}
		var usuario_logado = {/literal}{php}echo $_SESSION['Zend_Auth']['storage']['id']{/php}{literal}

        $("#form_proposta").validate({
            rules: {
	            data_proximo_contato: { required: true},
	        	status_proposta: { required: true}
            },
            messages: {
                data_proximo_contato: {required: "Obrigatorio"},
                status_proposta: {required: "Obrigatorio"}
            },
            submitHandler: function(form) {
                
                $("#nome").attr("readonly",false);
                $("#responsavel").attr("readonly",false);
                $("#email").attr("readonly",false);
                $("#fone1").attr("readonly",false);
                $("#fone2").attr("readonly",false);
                
				jqAjaxForm(form, "div_mensagem");
			}
        });

        populaSelect("plano", "{/literal}{$_site.url}{literal}", "plano/select-plano?cod={/literal}{$proposta->plano_id}{literal}");

        if (cod!="")
        {
	        {/literal}
	       	{foreach name=lista from=$servicos item=servico key=k}
	       		adicionarLinhaServico("tpl_proposta", "div_proposta_servico", false, {$k+1}, $('#plano').val(), '{$servico->servico_id}', '{$servico->int_quantidade_unidades}', '{$servico->flt_valor}', '{$_site.url}');
	       	{/foreach}
	       	{literal}
        }

		populaSelect("status_proposta", "{/literal}{$_site.url}{literal}", "proposta/select-status-proposta?cod={/literal}{$proposta->int_status}{literal}");

        populaSelect("usuario", "{/literal}{$_site.url}{literal}", "usuario/select-usuario?cod="+usuario_logado);
        
		$("#data_solicitacao").mask("99/99/9999");
		$("#data_proximo_contato").mask("99/99/9999");
		$("#fone1").mask("(99)9999-9999");
		$("#fone2").mask("(99)9999-9999");
		
        $('#data_proximo_contato').datepick({showOn: 'both'});

    }); //fecha $(

    $("#desconto").priceFormat();
    $("#valor_total").priceFormat();
    
    $("#nome").attr("readonly",true);
    $("#responsavel").attr("readonly",true);
    $("#plano").attr("disabled",true);
    $("#email").attr("readonly",true);
    $("#fone1").attr("disabled",true);
    $("#fone2").attr("disabled",true);
    $("#data_solicitacao").attr("disabled",true);
    $("#desconto").attr("disabled",true);
    $("#valor_total").attr("disabled", true);
    $("#valor_final").attr("disabled", true);

    var valor_final = {/literal}{$proposta->flt_valor_total-$proposta->flt_valor_total*$proposta->flt_desconto/100}{literal};
    $("#valor_final").val(valor_final);

	function mostraOcultaCampoMotivo(cod_status){
		if(cod_status == {/literal}{php}echo Constantes::cteCodStatusPropostaCancelada{/php}{literal}){
			$("#campo_motivo").show();
		}else{
			$("#campo_motivo").hide();
		}
	}
</script>
{/literal}
<form id="form_proposta" name="form_proposta" method="post" action="{$_site.url}{$acao}">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mvTituloFundo">
				  <tr>
					<td>
					{if $proposta->id > 0}Editar{else}Nova{/if} Proposta
					<input type="hidden" name="cod" value="{$proposta->id}"/>
					</td>
				  </tr>
				</table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">        
          <tr>
            <td class="contForm">
            
            <table width="100%" border="0" cellspacing="3" cellpadding="0">
                <tr>
                  <td width="30%" valign="top" class="fundoTituloForm">Nome do cliente:&nbsp;&nbsp;</td>
                  <td class="bordaFormResp" colspan="3"><input name="nome" type="text" autocomplete="off" class="formulario tamanhoForm" id="nome" value="{$proposta->vhr_nome}" maxlength="100">
                  	<div id="caixa_de_nomes_preatendimento" style="width:70%; display:none; padding:3px; background-color:#CFDCE4; border:1px #CCCCCC solid" >
						<div id="lista_de_nomes_preatendimento"></div>
					</div>
                  </td>
                </tr>
                <tr>
                  <td width="30%" valign="top" class="fundoTituloForm">Respons&aacute;vel:&nbsp;&nbsp;</td>
                  <td class="bordaFormResp" colspan="3"><input name="responsavel" type="text" class="formulario tamanhoForm" id="responsavel" value="{$proposta->vhr_responsavel}" maxlength="100"/></td>
                </tr>
                <tr>
                  <td valign="top" class="fundoTituloForm">Plano oferecido:</td>
                  <td width="70%" class="bordaFormResp" colspan="3">
						<select id="plano" name="plano" onchange="setaValorPlano('valor_plano','valor_total','valor_final',this.options[this.selectedIndex].id);"></select>
					</td>
                </tr>
                <tr>
                  <td valign="top" class="fundoTituloForm">E-mail:</td>
                  <td width="70%" class="bordaFormResp" colspan="3"><input name="email" type="text" class="formulario tamanhoForm" id="email" value="{$proposta->vhr_email}" /></td>
                </tr>
                <tr>
                  <td valign="top" class="fundoTituloForm">Fone 01:</td>
                  <td width="70%" class="bordaFormResp" colspan="3"><input name="fone1" type="text" class="formulario" id="fone1" value="{$proposta->vhr_fone1}" /></td>
                </tr>
                <tr>
                  <td valign="top" class="fundoTituloForm">Fone 02:</td>
                  <td width="70%" class="bordaFormResp" colspan="3"><input name="fone2" type="text" class="formulario" id="fone2" value="{$proposta->vhr_fone2}" /></td>
                </tr>
                <tr>
                  <td width="30%" valign="top" class="fundoTituloForm">Data de solicita&ccedil;&atilde;o da proposta:</td>
                  <td class="bordaFormResp" colspan="3"><input name="data_solicitacao" type="text" class="formulario" id="data_solicitacao" value="{if $proposta->id > 0}{$proposta->dte_solicitacao|date_format:"%d/%m/%Y"}{else}{$smarty.now|date_format:"%d/%m/%Y"}{/if}" /></td>
                </tr>
                <tr>
                  <td width="30%" valign="top" class="fundoTituloForm">Data do pr&oacute;ximo contato:</td>
                  <td class="bordaFormResp"><input name="data_proximo_contato" type="text" class="formulario" id="data_proximo_contato" value="{$atividade->dte_data|date_format:"%d/%m/%Y"}" /></td>
                  <td nowrap="nowrap" class="fundoTituloForm">Usu&aacute;rio que far&aacute; o contato:&nbsp;</td>
                  <td class="bordaFormResp"><select name="usuario" id="usuario"></select></td>
                </tr>
                <tr>
                  <td valign="top" colspan="4" align="right" class="fundoTituloForm beta bold terra">
                 	Desconto (em %): <input id="desconto" name="desconto" size="10" type="text" class="bold terra" maxlength="6" value="{$proposta->flt_desconto}" /> 
                  </td>
                </tr>
                <tr>
                  <td valign="top" colspan="4"  align="right" class="fundoTituloForm zeta bold terra">
                  <input type="hidden" name="valor_plano" id="valor_plano"></input>
                  Valor total: <input type="text" size="10" name="valor_total" id="valor_total" class="gama bold terra" value="{$proposta->flt_valor_total}"> 
                  </td>
                </tr>
                <tr>
                  <td valign="top" colspan="4"  align="right" class="fundoTituloForm zeta bold terra">
                  Valor Final: <input type="text" size="10" name="valor_final" id="valor_final" class="gama bold terra" value=""> 
                  </td>
                </tr>
                <tr>
                  <td valign="top" class="fundoTituloForm">Status:</td>
                  <td width="70%" class="bordaFormResp" colspan="3"><select id="status_proposta" name="status_proposta" onchange="mostraOcultaCampoMotivo(this.value);"></select></td>
                </tr>
                <tr id="campo_motivo" style="display:none">
                  <td valign="top" class="fundoTituloForm">Motivo cancelamento:</td>
                  <td width="70%" class="bordaFormResp" colspan="3"><textarea name="motivo" id="motivo" rows="7" class="formulario tamanhoForm">{$proposta->txt_motivo_cancelamento}</textarea></td>
                </tr>
            </table>
            
            </td>
          </tr>
  		<tr>
            <td class="paddingTop15 paddingBottom15" align="center"><!-- === Botões ( Salvar e Limpar ) === -->
                <span class="paddingRight15">
                	<input type="submit" value="Salvar" class="botao">
                </span>
              <span class="paddingRight15">
              <input name="limpar" type="reset" id="Limpar" value="Limpar" class="botao" />
              </span>
              <input type="button" value="Cancelar" onclick="cancelar(); return false;" class="botao">
                <!-- Final === Botões ( Salvar e Limpar ) === -->                      </td>
          </tr>
        </table>	
    </form>
